#!/usr/bin/sh
modprobe sagemcomtype
boxtype=`cat /proc/boxtype`

if [ $boxtype == 'uhd88' ]; then
  echo "Init LED"
  modprobe front_led
else
  echo "Init VFD"
  modprobe front_vfd
fi

if [ -e /var/etc/.firstboot ]; then
   echo "WAIT 1st start" >/dev/vfd
   echo "WAIT 1st start"
   rm /var/etc/.firstboot
   sleep 1
   touch /dev/.devfsd
fi

if [ -e /etc/init.d/mountvirtfs ]; then
   /etc/init.d/mountvirtfs start
fi
if [ -e /etc/init.d/portmap ]; then
   /etc/init.d/portmap start
fi

# start automounter with umount timeout of 5 seconds
if [ -e /lib/modules/2.6.32.71_stm24_0217/extra/autofs4 ]; then
	modprobe autofs4
	/usr/sbin/automount --timeout=5 /autofs file /etc/auto.usb
fi

if [ ! -e /var/etc/.firstboot ]; then
   
   modprobe e2_proc

   echo "Starting DEBUG Interface"
if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi

   echo "init stmfb"
   modprobe stmcore-display-sti7105
   modprobe stmfb display0=1280x720-32@50:16m:pal:yuv:yuv;

   echo "LOADING MODULES"   
   echo "LOADING MODULES" >/dev/vfd

   echo "load a firmware"
   /usr/bin/ustslave /dev/st231-1 /boot/audio.elf

   echo "load v firmware"
   /usr/bin/ustslave /dev/st231-0 /boot/video.elf

   echo "init embx"
   modprobe embxshell
   modprobe embxmailbox mailbox0=0xfe211000:136:set2 mailbox1=0xfe212000:0 ;
   modprobe embxshm mailbox0=shm:0:7:0x60000000:0:256:256:0:512:0x40000000:0x10000000 ;
   modprobe mme_host transport0=shm

	echo "init AVS"
	modprobe avs type=ak4708

	echo "init player 191"
	modprobe mmelog
	modprobe ksound
	modprobe p2div64
	modprobe stm_v4l2
	modprobe pseudocard

	if [ $boxtype == 'uhd88' ]; then
		modprobe fe-core box_type=1
	else
		modprobe fe-core box_type=0
	fi
    
	echo "init drivers"
	modprobe pti
	modprobe stm_monitor
	modprobe stmsysfs
	modprobe stmdvb
    modprobe player2 discardlateframe=0
	modprobe sth264pp
	modprobe stmalloc
	modprobe platform

   if [ -e /lib/modules/2.6.32.71_stm24_0217/extra/bpamem ]; then
        modprobe bpamem
        mknod /dev/bpamem0 c 153 0
   fi

   showiframe -p /usr/share/bootlogo.mvi &
   stfbcontrol a 0

   echo "init frontpanel"
   modprobe simu_button

   echo "init lircd"
      /usr/bin/lircd

   mknod /dev/rc c 147 1

      /usr/bin/evremote2 &

   echo "starting vsftpd"
if [ -e /etc/init.d/vsftpd ]; then
   /etc/init.d/vsftpd start
fi
   /usr/sbin/inetd

   #timefix e2 in format MMDDhhmmYYYYY.ss
   date -s "121220001970"

   stfbcontrol a 255

   until false
   do
      echo "starting e2->"
      /usr/bin/enigma2
      rtv=$?
      echo "e2 ended <- RTV: " $rtv
      case "$rtv" in
		0) echo "0"
		   echo "E2 ERROR" > /dev/vfd
		   sync
		   init 6;;
		1) echo "1"
		   echo "SHUTDOWN" > /dev/vfd
		   sync
		   init 0
		   umount -a;;
		2) echo "2"
		   echo "REBOOT" > /dev/vfd
		   sync
		   init 6;;
		3) echo "3"
		   echo "E2 RESTART" > /dev/vfd
		   echo "0" > /proc/progress
		   showiframe -p /usr/share/bootlogo.mvi &;;
		*) echo "*"
		   echo "ERROR" > /dev/vfd
		   sync
		   echo "0" > /proc/progress
		   showiframe -p /usr/share/bootlogo.mvi &;;
      esac
   done
  fi
 fi
fi
